from django.core.management.base import BaseCommand 
from ability.models import  UserProfile,Admin
import hashlib
class Command(BaseCommand):
    help = 'create admin user '

    def add_arguments(self, parser):
      parser.add_argument('username', type=str)
      parser.add_argument('pwd', type=str)
      parser.add_argument('email', type=str)

    def handle(self, *args, **options):
      user = UserProfile()
      user.set_password(options['pwd'])
      user.phone = str(options['username'])
      user.pwd = hashlib.md5(options['pwd'].encode()).hexdigest()
      user.email = str(options['email'])
      user.user_status = 'N'
      user.username = str(options['username'])
      user.user_type = "A"
      user.real_name = options['username']
      user.save()

      # 添加用户到admin表
      Admin.save(user)